package cn.tedu.websocket.demo.timer;

import cn.tedu.websocket.demo.pojo.WebSocketMessage;
import cn.tedu.websocket.demo.servers.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@EnableScheduling
public class SendMessageTime {
    private WebSocketServer webSocketServer;
    @Autowired
    public void setWebSocketServer(WebSocketServer webSocketServer) {
        this.webSocketServer = webSocketServer;
    }
    @Scheduled(fixedRate = 15000)
    public void sendMessage() {
        WebSocketMessage<String> message = new WebSocketMessage<>();
        message.setState(200);
        message.setMessage("成功");
        message.setData(System.currentTimeMillis() + ": 固定速率任务执行");
        webSocketServer.sendMessage(7, message);

    }
}
